from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
    # Launch arguments
    use_sim_time_arg = DeclareLaunchArgument(
        'use_sim_time',
        default_value='true',
        description='Use simulation time'
    )
    
    vehicle_model_arg = DeclareLaunchArgument(
        'vehicle_model',
        default_value='sample_vehicle',
        description='Vehicle model name'
    )
    
    map_path_arg = DeclareLaunchArgument(
        'map_path',
        default_value='',
        description='Path to map file'
    )
    
    # Include planning launch
    planning_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([
            PathJoinSubstitution([
                FindPackageShare('tools'),
                'launch',
                'planning.launch.py'
            ])
        ]),
        launch_arguments={
            'use_sim_time': LaunchConfiguration('use_sim_time'),
            'vehicle_model': LaunchConfiguration('vehicle_model'),
        }.items()
    )
    
    # Include simulator launch
    simulator_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([
            PathJoinSubstitution([
                FindPackageShare('tools'),
                'launch',
                'simulator.launch.py'
            ])
        ]),
        launch_arguments={
            'use_sim_time': LaunchConfiguration('use_sim_time'),
            'map_path': LaunchConfiguration('map_path'),
        }.items()
    )

    return LaunchDescription([
        use_sim_time_arg,
        vehicle_model_arg,
        map_path_arg,
        simulator_launch,
        planning_launch,
    ])